package edu.nf.vac.admin.controller;

import edu.nf.vac.admin.vo.ResultVO;
import edu.nf.vac.announcement.dao.AnnouncementDTO;
import edu.nf.vac.announcement.dao.AnnouncementPageDTO;
import edu.nf.vac.announcement.service.AnnouncementService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : QYM
 * @create 2022/4/5
 */
@RestController
public class AnnouncementController extends BaseController{
    @DubboReference(interfaceClass = AnnouncementService.class,version = "1.0.0")
    private AnnouncementService announcementService;

    /**
     * 查询公告列表
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/announcement/list")
    public ResultVO<List<AnnouncementDTO>> listAnnouncement(int page,int limit){
        AnnouncementPageDTO pageDTO = announcementService.listAnnouncement(page, limit);
        return pageResult(pageDTO.getTotal(),pageDTO.getList());
    }

    /**
     * 增加公告
     * @param dto
     */
    @PostMapping("/announcement/save")
    public ResultVO addAnnouncement(AnnouncementDTO dto){
        announcementService.addAnnouncement(dto);
        return success();
    }

    /**
     * 根据ID查询公告的列表
     * @param id
     * @return
     */
    @PostMapping("/announcement/{id}")
    public ResultVO<AnnouncementDTO> getAnnouncementById(@PathVariable("id") int id){
        AnnouncementDTO dto = announcementService.getAnnouncementById(id);
        return success(dto);
    }

    /**
     * 更新公告
     * @param dto
     */
    @PostMapping("/announcement/update")
    public ResultVO updateAnnouncement(AnnouncementDTO dto){
        announcementService.updateAnnouncement(dto);
        return success();
    }
}
